package cn.findviewbydream.controller;

import cn.findviewbydream.dto.Result;
import cn.findviewbydream.entity.UserEntity;
import cn.findviewbydream.service.UserService;
import cn.findviewbydream.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

/**********************************
 * 工程：cn.findviewbydream.controller
 * 作者：白雨濃 evil
 * 时间：17-6-1 下午9:33
 * 邮箱：evilbai@foxmail.com
 * 内容：用户类操作，包含注册，登录等功能
 **********************************/
@RestController
@RequestMapping("/user")
public class UserController
{
    private final UserService service;

    @Autowired
    public UserController(UserService service)
    {
        this.service = service;
    }

    @PostMapping("/login")
    public Result login(String userId, String password, HttpSession session)
    {
        return ResultUtil.success(service.login(userId, password, session));
    }

    @PostMapping("/register")
    public Result register(@Valid UserEntity entity, BindingResult result)
    {
        return ResultUtil.success(service.register(entity));
    }

}
